##################################
#-*- coding:utf8 -*-             #
import  download
import  google
import  script_a
def google_key(i):
    data_begin=2455122
    date_end=data_begin+10
    date_range="++daterange:"+'%d-'%(data_begin)+'%d'%(date_end)
    print date_range    
    #
    domain=""#"cn+OR+ru+OR+us"
    num="&num=100"
    pagenumber='&start=%d'%(i*100)
    pattern="+script+src+http+%22+-google"
    search_criteria="http://www.google.cn/search?hl=zh-CN&lr="+num+"&newwindow=1&q="+domain+"+%22title+script+src+http+%22+-google&"+pagenumber+"&sa=N"
    #search_criteria="http://www.google.com/search?hl=en&newwindow=1&rlz=1B3GGGL_zh-CN___KR206&pwst=1&q=%22title%3F%3E%3F%3C%3Fscript%3Fsrc%3F%3D%3Fhttp%3F%22"+domain+exception+date_range+"&start="+'%d'%(i*10)+'&sa=N'
    print search_criteria
    return search_criteria
def check_one_page(i):
    download_file=download.run(google_key(i))
    google.parser(download_file, script_a.element_handle)

def main():
    i=0
    x=0
    while i<10:
        x+=check_one_page(i)
        print 'find',x
        i+=1
    print  '!!!!!!!!!!totally injected site %d'%x   
                
def test():
#    url=http://search.yahoo.com/search?p=%22script+src+http%22&xargs=0&pstart=1&b=201&xa=20MPjLt3NVAgLB8GodsY1Q--,1256957621
#        http://search.yahoo.com/search?p=%22script+src+http%22&xargs=0&pstart=1&b=301&xa=7RBHjKweNvbdrjgE2sPiNw--,1256957637
    #out=download.d("http://www.google.cn/search?q=script%20src%20http%20script&hl=zh-CN&rlz=1B3MOZA_zh-CNCN326CN327&sa=G&tbo=1&num=100&newwindow=1&tbs=sbd:1,qdr:d")
    #out=download.d("http://www.google.cn/search?hl=zh-CN&rlz=1B3MOZA_zh-CNCN326CN327&tbo=1&num=100&newwindow=1&tbs=sbd:1,qdr:d&q=script+src+http+script&start=200&sa=N&filter=0")
    out=download.run("http://www.soso.com/q?w=script%20src%20http&lr=&sc=web&ch=w.p&filter=1&num=10&gid=&cin=&site=&pg=11&fil=1&tf=d")
#    print searchparser.p(out)
#test()
#main()
def test2():
    google.parser(download.new_output(), script_a.element_handle)
    
test2()

        


